console.log('FreeboxLink 2.0....');

var NotificationCS = function(notification) {
	
	var bindObject;
	
	this.bind = function(obj) {
		bindObject = obj;
	}
	
	this.getBindObject = function() {
		return bindObject;
	}
	
	this.onNotificationSubmit = function() {
	}
	
	this.onNotificationClose = function() {
	}
	
};

NotificationCS.init = function() {
	chrome.runtime.onMessage.addListener(NotificationCS.onmessage);
}

NotificationCS.lastNotification = null;
/**
 * Renvoie le dernier objet Notification crée
 */
NotificationCS.getNotification = function() {
	return NotificationCS.lastNotification;
}
NotificationCS.onmessage = function(request, sender, sendResponse) {
	if (request.notificationCS) {
		var notif = request.notificationCS;
		console.log("notificationAction: "+notif.type);
		
		if (notif.type == "create") {
			var d = document.createElement("div");
			d.innerHTML = notif.html;
			$$("body")[0].appendChild(d);
			var oldWindowAttr = {};
			for (var i in window) {
				oldWindowAttr[i] = true;
			}
			var n = new NotificationCS();
			NotificationCS.lastNotification = n;
			for (var i = 0; i < notif.js.length; i++) {
				eval(notif.js[i]);
			}
			console.log(NotificationCS.lastNotification.getBindObject());
			console.log("comparaison");
			console.log(typeof(window.getMaxZIndex));
			for (var i in window) {
				if (!oldWindowAttr[i]) {
					console.log("nouveau: "+i);
				}
			}
			
		}
		
	}
}

NotificationCS.init();

function notification() {
	return "truc";
}